<?php
function global_init()
{
	
	// HTTP
	define('HTTP_SERVER', base_url());
	define('HTTP_IMAGE', base_url().'images/');
	define('HTTP_ADMIN', base_url().'/office/');
	
	// HTTPS
	define('HTTPS_SERVER', base_url());
	define('HTTPS_IMAGE', base_url().'images/');
	
	
	$CI =& get_instance();
	
	
		
	// Settings
	$CI->load->library('cconfig');
		
	// Log
	$CI->load->library('Log', array('filename' => $CI->cconfig->get('config_error_filename')));
	
	//Language
	
	
	if (($CI->input->server('REQUEST_METHOD') == 'POST') && $CI->input->post('language_code')) {
			$CI->session->set_userdata('language_code', $CI->input->post('language_code'));
			
			
		
			if ($CI->input->post('redirect')) {
				redirect($CI->input->post('redirect'));
			} else {
				redirect(site_url().'/common/home');
			}
    }		
						
	if($CI->session->userdata('language_code') == '')
	{
		
		if($CI->cconfig->get('config_language') == "en")
		{
			$CI->session->set_userdata('language_code', 'english');		
		}
		else
		{
			$CI->session->set_userdata('language_code', $CI->cconfig->get('config_language'));		
		}
		
		
	}	
	
	if($CI->session->userdata('language_code') == 'en')
	{
		$CI->session->set_userdata('language_code', 'english');		
	}
	//$CI->session->set_userdata('language_code', 'zh-HK');

	$CI->config->set_item('language', $CI->session->userdata('language_code'));
	
	$CI->load->model('localisation/Model_Language');
	
	if($CI->session->userdata('language_code') == "english")
	{
		$lang_id = 	$CI->Model_Language->getLanguageID('en');
	}
	else
	{
		$lang_id = $CI->Model_Language->getLanguageID($CI->session->userdata('language_code'));
	}
	
	$CI->cconfig->set('config_language_id', $lang_id);	
	$CI->lang->load($CI->session->userdata('language_code'));	

	// Customer
	$CI->load->library('Customer');
	
	// Currency
	$CI->load->library('Currency');
	
	// Tax
	$CI->load->library('Tax');
	
	// Weight
	$CI->load->library('Weight');
	
	// Cart
	$CI->load->library('Hkcart');
	
	// Mail
	$CI->load->library('Hmail');
}
?>